package com.naiterui.ehp.bs.consult.controller;

import com.naiterui.common.repository.page.PageParamVO;
import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.bo.groupConsult.GroupConsultPreSignBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.context.ResourceHolder;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bs.consult.service.IVideoConsultService;
import com.naiterui.ehp.bs.consult.vo.GroupConsultApplyVO;
import com.naiterui.ehp.bs.consult.vo.GroupConsultListVO;
import com.naiterui.ehp.bs.consult.vo.GroupConsultOpinionConfirmVO;
import com.naiterui.ehp.bs.consult.vo.GroupConsultOpinionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 视频会诊
 *
 * @author gaoliangliang
 * @version 1.0
 * @date 2022-07-05 10:29
 **/
@Api(tags = SwaggerTag.VIDEO + SwaggerTag.GROUP_CONSULT)
@RestController
@RequiredArgsConstructor
@RequestMapping("/group/consult")
@Slf4j
@Validated
public class GroupConsultController {

    private final IVideoConsultService videoConsultService;

    @GetMapping("apply")
    @ApiOperation(value = "会诊申请信息")
    @ApiImplicitParam(name = "videoConsultId", value = "视频咨询id", required = true, dataType = "long", paramType = "query")
    public GroupConsultApplyVO groupConsultInfo(Long videoConsultId, Long doctorId) throws BusinessException {
        if (doctorId == null) {
            doctorId = (Long) ResourceHolder.getResource(SettingConfig.DOCTOR_ID);
        }
        return videoConsultService.groupConsultInfo(videoConsultId, doctorId);
    }

    @PostMapping("apply")
    @ApiOperation(value = "申请会诊")
    public void groupConsultInfo(@RequestBody GroupConsultApplyVO groupConsultApplyVO) throws BusinessException {
        videoConsultService.groupConsultApply(groupConsultApplyVO);
    }

    @GetMapping("info")
    @ApiOperation(value = "会诊列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, dataType = "long", paramType = "query")})
    public PageVO<GroupConsultListVO> groupConsultList(Long doctorId, PageParamVO pageParamVO) throws BusinessException {
        if (doctorId == null) {
            doctorId = (Long) ResourceHolder.getResource(SettingConfig.DOCTOR_ID);
        }
        return videoConsultService.groupConsultList(doctorId, pageParamVO);
    }

    @GetMapping("info/{videoConsultId}")
    @ApiOperation(value = "会诊概要信息")
    @ApiImplicitParam(name = "videoConsultId", value = "视频咨询id", required = true, dataType = "long", paramType = "query")
    public GroupConsultListVO groupConsultDetail(@PathVariable Long videoConsultId) throws BusinessException {
        return videoConsultService.groupConsultDetail(videoConsultId);
    }

    @PostMapping("opinion")
    @ApiOperation(value = "申请意见发起签署")
    public GroupConsultPreSignBO groupConsultOpinion(@RequestBody GroupConsultOpinionVO groupConsultOpinionVO) throws BusinessException {
        return videoConsultService.groupConsultOpinion(groupConsultOpinionVO);
    }

    @PostMapping("opinion/confirm")
    @ApiOperation(value = "申请意见签署确认")
    public void groupConsultOpinionConfirm(@RequestBody GroupConsultOpinionConfirmVO groupConsultOpinionConfirmVO) throws BusinessException {
        videoConsultService.groupConsultOpinionConfirm(groupConsultOpinionConfirmVO);
    }

    @PostMapping("/finish/{roomId}")
    @ApiOperation(value = "结束会诊")
    public void finish(@PathVariable Integer roomId) throws BusinessException {
        this.videoConsultService.groupConsultFinish(roomId);
    }
}